package com.ming.rabbitmq.four;

import com.ming.rabbitmq.util.RabbitMqUtils;
import com.ming.rabbitmq.util.SleepUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

public class Worker1 {
    public static final  String name  ="ack";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
//        不公平分发  给空闲消费者分发更多
//        0公平 1不公平 1以上n代表信道最多n条未处理消息（预处理）
        channel.basicQos(1);
        DeliverCallback deliverCallback = (consumerTage, message)->{
            SleepUtils.sleep(1);
            System.out.println("1秒后消息已收到");
            System.out.println(new String(message.getBody()));
//            手动应答                                                 ↓是否批量应答
            channel.basicAck(message.getEnvelope().getDeliveryTag(),false);
        };
        CancelCallback cancelCallback = (consumerTag)->{
            System.out.println("消息已取消");
            System.out.println(consumerTag);
        };
        System.out.println("Worker1等待中");
//                          哪个队列 是否自动应答 接收消息回调 取消消息的回调
        channel.basicConsume(name,false,deliverCallback,cancelCallback);

    }
}
